<?php
/**
 * Created by PhpStorm.
 * User: Tomkk
 * Date: 2016/5/5
 * Time: 18:45
 */

//code              含义
// 0                成功
// 1                服务器错误
// 2                业务错误
function success($code, $value){
    $arr = array('code'=>$code,'returnValue'=>$value);
    if(is_array($arr['returnValue'])) {//如果是数组就遍历编码
        foreach ($arr['returnValue'] as $row) {
                foreach ($row as $key => $col) {
                    $row[$key] = urlencode($col);
            }
        }
    }else{//如果不是数组就直接编码
        $arr['returnValue'] = urlencode($arr['returnValue']);
    }
    return urldecode (json_encode($arr,JSON_UNESCAPED_UNICODE));//json不编码unicode
}

function error($code, $reason){
    $arr = array('code'=>$code,'errorReason'=>$reason);
    foreach ( $arr as $key => $value ) {
        $arr[$key] = urlencode ( $value );
    }
    return urldecode (json_encode($arr));
}

